package com.tools.cleanmaster.ui.activity;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;

import com.tools.cleanmaster.R;
import com.tools.cleanmaster.manager.NotificationSceneManager;
import com.tools.cleanmaster.ui.notification.NotificationBaseItem;
import com.tools.cleanmaster.ui.notification.item.BatteryLowItem;
import com.tools.cleanmaster.ui.notification.item.BatterySharpDecItem;
import com.tools.cleanmaster.ui.notification.item.CpuCoolerItem;
import com.tools.cleanmaster.ui.notification.item.NetflowScreenOffItem;
import com.tools.cleanmaster.ui.notification.item.TotalCpuUtilizationItem;
import com.tools.cleanmaster.ui.notification.item.TotalMemoryUsageItem;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class SceneTestActivity extends ListActivity implements AdapterView.OnItemClickListener {
    public interface FuncExecute {
        void action();
    }

    private List<String> mFuncNamelist = new ArrayList<String>();
    private Map<String, FuncExecute> mFuncMap = new LinkedHashMap<String, FuncExecute>();

    private void initFunctionMap() {
        mFuncMap.put("LandingPage-低电量提示", new FuncExecute() {
            @Override
            public void action() {
                NotificationBaseItem item = new BatteryLowItem();
                item.checkRules();
                NotificationSceneManager.getInstance().showSceneNotification(item);
            }
        });
        mFuncMap.put("LandingPage-短时间内耗电过快", new FuncExecute() {
            @Override
            public void action() {
                NotificationBaseItem item = new BatterySharpDecItem();
                item.checkRules();
                NotificationSceneManager.getInstance().showSceneNotification(item);
            }
        });
        mFuncMap.put("LandingPage-锁屏后频繁使用网络流量", new FuncExecute() {
            @Override
            public void action() {
                NotificationBaseItem item = new NetflowScreenOffItem("com.tencent.mm");
                item.checkRules();
                NotificationSceneManager.getInstance().showSceneNotification(item);
            }
        });
        mFuncMap.put("LandingPage-总CPU占用过高", new FuncExecute() {
            @Override
            public void action() {
                NotificationBaseItem item = new TotalCpuUtilizationItem(100);
                item.checkRules();
                NotificationSceneManager.getInstance().showSceneNotification(item);
            }
        });
        mFuncMap.put("LandingPage-总内存占用过高", new FuncExecute() {
            @Override
            public void action() {
                NotificationBaseItem item = new TotalMemoryUsageItem(85);
                item.checkRules();
                NotificationSceneManager.getInstance().showSceneNotification(item);
            }
        });
        mFuncMap.put("CPU降温", new FuncExecute() {
            @Override
            public void action() {
                NotificationBaseItem item = new CpuCoolerItem();
                item.checkRules();
                NotificationSceneManager.getInstance().showSceneNotification(item);
            }
        });

        mFuncNamelist.addAll(mFuncMap.keySet());
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.scene_listview);
        initFunctionMap();
        ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mFuncNamelist);
        ListView listview = getListView();
        listview.setAdapter(adapter);
        listview.setOnItemClickListener(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        String functionName = mFuncNamelist.get(position);
        FuncExecute execute = mFuncMap.get(functionName);
        execute.action();
    }
}
